<?php
namespace Admin\Controller;
use Think\Controller;
/*
*后台公用控制器
*/
class MemberController extends CommonController {

	public function index(){

		$this->display();
	}

	public function memberHandle(){

		$User = D('VerifyRelation');

		$verifyUser = $User->field('password', true)->relation(true)
						  ->where("user_status = 1")
						  ->order('user_id desc')
						  ->select();

		$verifyUserList = array();
		foreach ($verifyUser as $value) {
			foreach ($value['department'] as $va) {
				if ($va['dept_id'] == session('deptId')) {
					$verifyUserList[] = array(
						'user_id' => $value['user_id'],
						'user_name' => $value['user_name'],
						'user_stu_num' => $value['user_stu_num'],
						'user_dept' => $value['department']
					);
				}
			}
		}

		$this->ajaxReturn($verifyUserList, 'json');
	}

	public function memberDelete(){
		if (!IS_POST) error('页面不存在!');
		$userId = I('post.user_id');
		$data['user_status'] = '0';
		M('verify_user')->data($data)->where("user_id = $userId")->save();
	}

	public function memberpass(){
		if (!IS_POST) error('页面不存在!');
		$userId = I('post.user_id');
		$data['user_status'] = '0';
		M('verify_user')->data($data)->where("user_id = $userId")->save();
		$verifyUser = M('verify_user')->where("user_id = $userId")->find();
		$user = array(
			'user_name' => $verifyUser['user_name'],
			'user_password' => $verifyUser['user_password'],
			'user_stu_num' => $verifyUser['user_stu_num'],
			'user_log_time' => time(),
			'user_log_ip' => get_client_ip(),
			'user_status' => 1,
			);

		//所属部门
		$deptId = M('verify_user_dept')->where("user_id = $userId")->select();
		$info = array();

		$uid = M('user')->add($user);
		//添加部门和职务信息
		foreach ($deptId as $v) {
			$info[] = array(
				'dept_id' => $v['dept_id'],
				'role_id' => '2',		//默认学员
				'user_id' => $uid
				);
		}
		M('user_dept_role')->addAll($info);
	}
}
?>